﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.Data.SqlClient;
using System.Configuration;
using System.Globalization;
using System.Threading;
using ERPStudio;
using System.IO;
using System.Reflection;

namespace AMix
{
    class dscModule: ModuleClass
    {
        public dscModule(Int16 codUnit, String numeUnit,String theme)
            : base(codUnit, numeUnit,theme)
        {
            
        }

        /// <summary>
        /// returneaza ID-ul intern pentru autorizare - 
        /// deriva din numele modului si este o cheie de control
        /// </summary>
        /// <returns></returns>
        override public String GetModuleID()
        {
            return "20";
        }
        
      
        /// <summary>
        /// incarca meniul acestui modul
        /// </summary>
        /// <param name="myMenu"></param>
        new public void LoadMenu(ToolStripMenuItem mn, Form vForm, Guid appId, Guid userID)
        {
            base.LoadMenu(mn, (FrmMainMdi)vForm, appId, userID);
            InitStoredProcedure("Init_Amix");
        }

        public void Calculul_Amortizarii(object sender, EventArgs e)
        {
            OptiuniRapoarteFrm frm = new OptiuniRapoarteFrm(1,this);
            frm.MdiParent = mdiForm;
            frm.Show();
        }

        public void Repartizare_Amortizare(object sender, EventArgs e)
        {
            OptiuniRapoarteFrm frm = new OptiuniRapoarteFrm(2,this);
            frm.MdiParent = mdiForm;
            frm.Show();
        }
        public void StocFaptic(object sender, EventArgs e)
        {
            StocFapticFrm frm = new StocFapticFrm(this);
            frm.MdiParent = mdiForm;
            frm.Show();
        }

        public void Lista_Inventar(object sender, EventArgs e)
        {
            OptiuniRapoarteFrm frm = new OptiuniRapoarteFrm(3,this);
            frm.MdiParent = mdiForm;
            frm.Show();
        }

        public void Obiecte_Inventar(object sender, EventArgs e)
        {
            OptiuniRapoarteFrm frm = new OptiuniRapoarteFrm(6, this);
            frm.MdiParent = mdiForm;
            frm.Show();
        }

        public void Fisa_Mijlocului_Fix(object sender, EventArgs e)
        {
            OptiuniRapoarteFrm frm = new OptiuniRapoarteFrm(4,this);
            frm.MdiParent = mdiForm;
            frm.Show();
        }
        public void Lista_Documentelor(object sender, EventArgs e)
        {
            OptiuniRapoarteFrm frm = new OptiuniRapoarteFrm(5,this);
            frm.MdiParent = mdiForm;
            frm.Show();
        }
        public void Import(object sender, EventArgs e)
        {
            ImportFrm frm = new ImportFrm(this);
            frm.MdiParent = mdiForm;
            frm.Show();
        }
        //public void Reevaluare(object sender, EventArgs e)
        //{
        //    PreviewRaportFrm frm = new PreviewRaportFrm("ReevaluareMFIX.rdlc", null,this);
        //    ERPDataSet ERPDataSet = new ERPDataSet();

        //    BindingSource bs = new BindingSource(ERPDataSet, "dsc_ReevMFIX");
            
        //    SqlDataAdapter ta = new SqlDataAdapter("Select * from dsc_ReevMFIX", StudioForm.DeschideConexiune("ERPConnectionString"));
        //    ta.Fill(ERPDataSet.dsc_ReevMFIX);
        //    //ta.SelectCommand.CommandText = "SELECT * FROM pCfgLuna";
        //    //ta.Fill(persSalDataSet.pCfgLuna);

        //    frm.AddDataSource("ERPDataSet_dsc_ReevMFIX", bs);
        //    //frm.AddDataSource("pCfgLuna", bs1);
        //    //frm.AddParameter("Titlu", "Nr. personal/Functii", true);
        //    frm.MdiParent = mdiForm;
        //    frm.Show();
        //    StudioForm.InchideConexiune(ta.SelectCommand.Connection);
        //}
        //public void Nereevaluate(object sender, EventArgs e)
        //{
        //    PreviewRaportFrm frm = new PreviewRaportFrm("NeReevaluareMFIX.rdlc", null,this);
        //    ERPDataSet ERPDataSet = new ERPDataSet();

        //    BindingSource bs = new BindingSource(ERPDataSet, "dsc_NeReevMFIX");
            
        //    SqlDataAdapter ta = new SqlDataAdapter("Select * from dsc_NeReevMFIX", StudioForm.DeschideConexiune("ERPConnectionString"));
        //    ta.Fill(ERPDataSet.dsc_NeReevMFIX);
        //    //ta.SelectCommand.CommandText = "SELECT * FROM pCfgLuna";
        //    //ta.Fill(persSalDataSet.pCfgLuna);

        //    frm.AddDataSource("ERPDataSet_dsc_NeReevMFIX", bs);
        //    //frm.AddDataSource("pCfgLuna", bs1);
        //    //frm.AddParameter("Titlu", "Nr. personal/Functii", true);
        //    frm.MdiParent = mdiForm;
        //    frm.Show();
        //    StudioForm.InchideConexiune(ta.SelectCommand.Connection);
        //}

        public void Departamente(object sender, EventArgs e)
        {
            Type mModule = null;
            FrmRezumat frm =  (new StudioForm()).RuleazaFrm("erpforms", "ERPForms.DepartamenteFrm", new object[] { this}, out mModule) as FrmRezumat;
            if (frm!=null)
            {
                frm.ShowDialog();
            }
            
        }

        public void FisaMFix(object sender, EventArgs e)
        {
            MijlocFixFrm frm = new MijlocFixFrm(this,true);
            frm.MdiParent = mdiForm;
            frm.Show();
        }

        public void ObiecteInventar(object sender, EventArgs e)
        {
            MijlocFixFrm frm = new MijlocFixFrm(this,false);
            frm.MdiParent = mdiForm;
            frm.Show();
        }

        public void Gestionari(object sender, EventArgs e)
        {
            GestionariFrm frm = new GestionariFrm(this);
            frm.MdiParent = mdiForm;
            frm.Show();
        }

        public void Catalog(object sender, EventArgs e)
        {
            CatalogFrm frm = new CatalogFrm(this);
            frm.MdiParent = mdiForm;
            frm.Show();
        }

        public void Unitati_functionale(object sender, EventArgs e)
        {
            FrmMainMdi frm = mdiForm as FrmMainMdi;
            Assembly asm = frm.GetModule("erpforms");
            if (asm == null)
                return;
            String numeClasa = "ERPForms.UnitatiFrm";
            Type mModule = asm.GetType(numeClasa);

            if (mModule != null)
            {
                FrmRezumat newFrm = asm.CreateInstance(numeClasa, true, BindingFlags.Public | BindingFlags.Instance | BindingFlags.CreateInstance, null,
                   new object[] { this, false }, Thread.CurrentThread.CurrentCulture, new object[] { }) as FrmRezumat;

                newFrm.MdiParent = frm;
                newFrm.Show();
            }

        }
        public void Parametrizare(object sender, EventArgs e)
        {
            AmixSetupFrm frm = new AmixSetupFrm(this);
            frm.MdiParent = mdiForm;
            frm.Show();
        }

        
        public void Documente(object sender, EventArgs e)
        {
            DocAmixFrm frm = new DocAmixFrm(-1,this);
            frm.MdiParent = mdiForm;
            frm.Show();
        }

        public void UnitatiMasura(object sender, EventArgs e)
        {
            FrmMainMdi frm = mdiForm as FrmMainMdi;
            Assembly asm = frm.GetModule("erpforms");
            if (asm == null)
                return;

            String numeClasa = "ERPForms.UnitatiMasuraFrm";
            Type mModule = asm.GetType(numeClasa);

            if (mModule != null)
            {
                FrmRezumat newFrm = asm.CreateInstance(numeClasa, true, BindingFlags.Public | BindingFlags.Instance | BindingFlags.CreateInstance, null,
                    new object[] { this }, Thread.CurrentThread.CurrentCulture, new object[] { }) as FrmRezumat;

                newFrm.MdiParent = frm;
                newFrm.Show();
            }
        }


        /*
        public static void Note_Contabile(object sender, EventArgs e)
        {
            NoteContabileRezumatFrm frm = new NoteContabileRezumatFrm(null);
            frm.MdiParent = mdiForm;
            frm.Show();
        }

        public static void Evidenta_NotaContabila(object sender, EventArgs e)
        {
            NotaContabilaFrm frm = new NotaContabilaFrm();
            frm.MdiParent = mdiForm;
            frm.Show();
        }

        public static void Parametrizare(object sender, EventArgs e)
        {
            BalconSetupFrm frm = new BalconSetupFrm();
            frm.MdiParent = mdiForm;
            frm.Show();
        }
        public static void SeriiNumerice(object sender, EventArgs e)
        {
            SeriiNumericeRezumatFrm frm = new SeriiNumericeRezumatFrm();
            frm.MdiParent = mdiForm;
            frm.Show();
        }*/


    }
}
